#ifndef MBALBUMCOMPARISON_HPP_INCLUDED
#define MBALBUMCOMPARISON_HPP_INCLUDED

#include <musicbrainz3/webservice.h>
#include <musicbrainz3/query.h>
#include <musicbrainz3/track.h>
#include <musicbrainz3/artist.h>
#include <musicbrainz3/release.h>
#include <musicbrainz3/lists.h>
#include <musicbrainz3/disc.h>
#include <string>
#include <vector>
#include <iostream>
#include <qt4/QtXml/QtXml>
#include <qt4/QtSql/QtSql>
#include "../../model/AudioFile.hpp"

/*
Recherche d'artiste : http://musicbrainz.org/ws/1/artist/?type=xml&name=Tori+Amos
Recherche d'album :   http://musicbrainz.org/ws/1/release/?type=xml&title=Ocean&inc=+counts
http://musicbrainz.org/doc/XML_Web_Service
*/
/** Class to perform queries on the MusicBrain database and to compare with existing file list */
class MBAlbumComparison {
    private:
        //MusicBrainz objects
        MusicBrainz::WebService *ws;
        MusicBrainz::Query *q;
        MusicBrainz::ArtistFilter *af;
        MusicBrainz::ReleaseFilter *rf;
        MusicBrainz::ArtistResultList al;
        MusicBrainz::TrackFilter *tf;
        MusicBrainz::TrackResultList tl;
        MusicBrainz::ReleaseResultList rl;
        //filter parameters
        std::string artist, artistID, album, albumID, track, trackID;
        unsigned short tracks;
        unsigned short cds;
        unsigned int length; //in milliseconds
        //other objects
        std::vector<AudioFile*> local;
        std::vector<std::vector<AudioFile*> > remote;
    public:
        MBAlbumComparison();
        ~MBAlbumComparison();
        /** Search an album from various parameters */
        void search();
        /** Set the selected found album informations to local file contents
         * @param index: selected index
         * @param rename: true to rename files other wise false
        */
        void set(unsigned int i, bool rename);
        /** Search an artist from the given name and return all foud artist with their MusicBrainz ID */
        void searchArtist();
        void searchTrack();
        /** Get found artists */
        std::vector<MusicBrainz::ArtistResult*> getArtists();
        /** Get found releases */
        std::vector<MusicBrainz::ReleaseResult*> getReleases();
        /** Get found tracks */
        std::vector<MusicBrainz::TrackResult*> getTracks();

        //setters
        void setAlbum(std::string v);
        void setAlbumID(std::string v);
        void setArtist(std::string v);
        void setArtistID(std::string v);
        void setType(unsigned short v);
        void setTracks(unsigned short v);
        void setCDs(unsigned char v);

        //database inserts
        ///TODO: implementation
        static unsigned int addAlbum(QSqlDatabase db, MusicBrainz::Release *a);
        static unsigned int addArtist(QSqlDatabase db, MusicBrainz::Artist *a);
        static unsigned int addDisc(QSqlDatabase db, MusicBrainz::Disc *d);
};

#endif // MBALBUMCOMPARISON_HPP_INCLUDED
